$OJ=\sega\xmen\obj\sounds VB DA NOXR

;************************************
;* Project:	X-Men   	    *
;* Machine:	Sega Game Gear	    *
;* Processor:	Z80		    *
;* Author:	Paul Hutchinson	    *
;* (c) MCMXCIII	Sega of America	    *
;************************************

	public	FN_sound

;****************************************************
;sound subroutines written by Joergen Bech
;****************************************************
	public	music_ptrs
	public	Tune0

	public	player

;music\sfx externals from equates

	extern	MusicSpeed		;0=normal, 1=slow, 2=off
	extern	SFXToggle		;0=on, 1=off

	extern	psg
	extern	musical			;bit 7 set= no sfx/music, bit 0 set = use volume ramp data
	extern	paused			;0=game not paused, 1=game paused

	extern	Chan_0
	extern	Chan_0_stack
	extern	Chan_1
	extern	Chan_1_stack
	extern	Chan_2
	extern	Chan_2_stack
	extern	Noise_chan
	extern	Noise_stack
	extern	sfx_chan
	extern	sfx_stack
	extern	Master_volume_data
	extern	req_music
	extern	req_sfx

FN_sound:

sfx_ctr		equ	0
trk_dat_lo	equ	1
trk_dat_hi	equ	2
trk_stk_lo	equ	3
trk_stk_hi	equ	4
trk_spd		equ	5
not_num		equ	6
not_ctr_lo	equ	7
not_ctr_hi	equ	8
cur_ins_lo	equ	9
cur_ins_hi	equ	10
spc_sfx		equ	11
sfx_ptr_lo	equ	12
sfx_ptr_hi	equ	13
phase_1_lo	equ	14
phase_1_hi	equ	15
phase_2_lo	equ	16
phase_2_hi	equ	17

vol_dat_lo	equ	21
vol_dat_hi	equ	22
freq_lo		equ	23
freq_hi		equ	24
volume		equ	25
freq_bits	equ	26
vol_bits	equ	27
chan_off	equ	28
transpose	equ	29


StackSize	equ	32

;////// SOUND DRIVER //////

player:
	ld	a,(musical)
	bit	7,a
	jp	z,player_end

	ld	a,(paused)
	bit	0,a
	jp	nz,player_end

	push	bc
	push	de
	push	hl

	exx
	push	bc
	push	de
	push	hl
	exx

	push	ix

player_sfx:
	ld	a,(SFXToggle)
	or	a
	jr	nz,RemoveSFX

	ld	a,(req_sfx)
	or	a

	jp	z,player_music

	call	init_sfx
RemoveSFX:
	xor	a
	ld	(req_sfx),a

player_music:
	ld	a,(MusicSpeed)
	cp	2
	jr	z,RemoveMusic

	ld	a,(req_music)
	or	a
	
	jp	z,player_sfx_channel

	call	init_channels

RemoveMusic:
	xor	a
	ld	(req_music),a

player_sfx_channel:
	call	sfx_subroutine

player_master_volume:
	ld	a,(musical)
	bit	0,a
	jr	z,music_end

	ld	ix,master_volume_data
	ld	a,(ix+1)		;volume add
	or	a
	jr	z,player_channels
	dec	(ix+3)			;speed count
	jr	nz,player_channels
	add	a,(ix)			;master volume
	ld	(ix),a
	or	a
	jr	z,player_master_volume_off
	cp	14				;should be 16
	jr	z,player_master_volume_off
	ld	a,(ix+2)		;speed
	ld	(ix+3),a		;speed count
	jp	player_channels

player_master_volume_off:
	xor	a
	ld	(ix+1),a		;volume add

player_channels:
	ld	ix,chan_0	;process data
	call	player_subroutine
	ld	ix,chan_1
	call	player_subroutine
	ld	ix,chan_2
	call	player_subroutine
	ld	ix,noise_chan
	call	player_subroutine

music_end:
	pop	ix

	exx
	pop	hl
	pop	de
	pop	bc
	exx

	pop	hl
	pop	de
	pop	bc

player_end:
	ret



;////// PLAYER SUBROUTINE //////

player_subroutine:
	ld	e,(ix+not_ctr_lo)
	ld	d,(ix+not_ctr_hi)
	ld	a,e
	or	d		;check zero (first time routine is called)
	jp	z,ps_track

	dec	de

	ld	(ix+not_ctr_lo),e
	ld	(ix+not_ctr_hi),d

	ld	a,d
	or	e

	jp	z,ps_track




;special fx

ps_get_special_fx:
	ld	a,(ix+spc_sfx)
	or	a
	jp	z,ps_volume
	bit	5,a
	jp	nz,ps_waz
	bit	4,a
	jp	nz,ps_end
	bit	3,a
	jr	nz,ps_noise
	bit	2,a		;test vibrato (4)
	jp	nz,ps_vibrato
	bit	1,a		;test phase (2-3)
	jp	nz,ps_phase
	jp	ps_arpeggio

ps_waz:
	ld	l,(ix+sfx_ptr_lo)
	ld	h,(ix+sfx_ptr_hi)
	ld	a,h
	or	l
	jp	z,ps_volume
flad:
	ld	a,(hl)
	cp	goto
	jr	nz,lfad
	inc	hl
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	ex	de,hl
	jr	flad
lfad:
	inc	hl
	ld	(ix+sfx_ptr_lo),l
	ld	(ix+sfx_ptr_hi),h

	ld	e,a
	ld	d,0
	bit	7,e
	jr	z,nhin
	ld	d,0ffh
nhin:
	ld	l,(ix+freq_lo)
	ld	h,(ix+freq_hi)
     	add	hl,de
	ld	(ix+freq_lo),l
	ld	(ix+freq_hi),h
	jp	ps_volume



;noise

ps_noise:
	ld	l,(ix+sfx_ptr_lo)
	ld	h,(ix+sfx_ptr_hi)
	ld	a,l
	or	h
	jp	z,ps_volume

ps_noise_get_command:
	ld	a,(hl)
	inc	hl
	cp	goto
	jr	z,ps_noise_goto
	cp	enddata
	jr	z,ps_noise_enddata
	ld	(ix+sfx_ptr_lo),l
	ld	(ix+sfx_ptr_hi),h

	ld	(ix+freq_bits),a
	or	a
	jp	z,ps_volume	


	add	a,64
	ld	(ix+freq_bits),a
	jp	ps_volume

ps_noise_enddata:
	xor	a
	ld	(ix+sfx_ptr_lo),a
	ld	(ix+sfx_ptr_hi),a
	jp	ps_volume

ps_noise_goto:
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	jp	ps_noise_get_command



;arpeggio

ps_arpeggio:
	ld	l,(ix+sfx_ptr_lo)
	ld	h,(ix+sfx_ptr_hi)
	ld	a,l
	or	h
	jp	z,ps_volume

ps_arp_get_command:
	ld	a,(hl)
	inc	hl
	cp	goto
	jr	z,ps_arp_goto
	cp	enddata
	jr	z,ps_arp_enddata
	ld	(ix+sfx_ptr_lo),l
	ld	(ix+sfx_ptr_hi),h
	add	a,(ix+not_num)
	ld	(ix+not_num),a

	and	127
	ld	l,a
	ld	h,0
	add	hl,hl
	ld	de,frequency_table
	add	hl,de
	ld	a,(hl)
	inc	hl
	ld	(ix+freq_lo),a
	ld	a,(hl)
	ld	(ix+freq_hi),a
	jp	ps_volume

ps_arp_enddata:
	xor	a
	ld	(ix+sfx_ptr_lo),a
	ld	(ix+sfx_ptr_hi),a
	jp	ps_volume

ps_arp_goto:
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	jp	ps_arp_get_command



;phase

ps_phase:
	xor	1
	ld	(ix+spc_sfx),a
	bit	0,a
	jr	nz,ps_phase_2

ps_phase_1:
	ld	l,(ix+phase_1_lo)
	ld	h,(ix+phase_1_hi)
	ld	(ix+freq_lo),l
	ld	(ix+freq_hi),h
	jp	ps_phase_cont

ps_phase_2:
	ld	l,(ix+phase_2_lo)
	ld	h,(ix+phase_2_hi)
	ld	(ix+freq_lo),l
	ld	(ix+freq_hi),h
	jp	ps_volume

ps_phase_cont:
	ld	e,(ix+sfx_ptr_lo)
	ld	d,(ix+sfx_ptr_hi)

	ld	l,(ix+phase_1_lo)
	ld	h,(ix+phase_1_hi)
	add	hl,de
	ld	a,h
	cp	100b
	jr	nc,ps_phase_1_reverse

	push	de

	exx
	pop	de
	ld	l,(ix+phase_2_lo)
	ld	h,(ix+phase_2_hi)
	or	a
	sbc	hl,de
	ld	a,h
	cp	100b
	exx

	jr	nc,ps_phase_1_reverse

	ld	(ix+phase_1_lo),l
	ld	(ix+phase_1_hi),h

	exx
	ld	(ix+phase_2_lo),l
	ld	(ix+phase_2_hi),h
	exx

	jp	ps_volume

ps_phase_1_reverse:
	push	hl
	ld	hl,0
	xor	a
	sbc	hl,de
	ex	de,hl
	pop	hl
	add	hl,de
	add	hl,de
	ld	(ix+phase_1_lo),l
	ld	(ix+phase_1_hi),h
	ld	(ix+sfx_ptr_lo),e
	ld	(ix+sfx_ptr_hi),d

	push	de

	exx
	pop	de
	ld	l,(ix+phase_2_lo)
	ld	h,(ix+phase_2_hi)
	or	a
	sbc	hl,de
	ld	(ix+phase_2_lo),l
	ld	(ix+phase_2_hi),h
	exx

	jp	ps_volume



;vibrato

ps_vibrato:
	ld	l,(ix+sfx_ptr_lo)
	ld	h,(ix+sfx_ptr_hi)
	ld	a,l
	or	h
	jp	z,ps_volume

ps_vib_get_command:
	ld	a,(hl)
	inc	hl
	cp	goto
	jr	z,ps_vib_goto
	cp	enddata
	jr	z,ps_vib_enddata
	ld	(ix+sfx_ptr_lo),l
	ld	(ix+sfx_ptr_hi),h

	bit	7,a
	jr	nz,ps_vib_negative
	or	a
	jp	z,ps_volume

	ld	b,a
	ld	hl,vibrato_table
	ld	e,(ix+not_num)
	ld	d,0
	add	hl,de
	ld	e,(hl)
	ld	d,0
	ld	l,d
	ld	h,d
ps_vib_add_nxt_positive:
	add	hl,de
	djnz	ps_vib_add_nxt_positive
	ex	de,hl
	ld	l,(ix+freq_lo)
	ld	h,(ix+freq_hi)
	add	hl,de
	ld	(ix+freq_lo),l
	ld	(ix+freq_hi),h
	jp	ps_volume

ps_vib_negative:
	neg
	ld	b,a
	ld	hl,vibrato_table
	ld	e,(ix+not_num)
	ld	d,0
	add	hl,de
	ld	a,(hl)
	neg
	ld	e,a
	ld	d,255
	ld	hl,0
ps_vib_add_nxt_negative:
	add	hl,de
	djnz	ps_vib_add_nxt_negative
	ex	de,hl
	ld	l,(ix+freq_lo)
	ld	h,(ix+freq_hi)
	add	hl,de
	ld	(ix+freq_lo),l
	ld	(ix+freq_hi),h
	jp	ps_volume

ps_vib_enddata:
	xor	a
	ld	(ix+sfx_ptr_lo),a
	ld	(ix+sfx_ptr_hi),a
	jp	ps_volume

ps_vib_goto:
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	jp	ps_vib_get_command



;track commands

ps_track:
	ld	l,(ix+trk_dat_lo)
	ld	h,(ix+trk_dat_hi)
	ld	a,l
	or	h
	jp	z,ps_track_off

ps_track_get_command:
	ld	a,(hl)
	inc	hl

	bit	7,a
	jp	z,ps_note
	cp	192
	jp	nc,ps_note

	cp	pause
	jp	z,ps_track_pause
	cp	loop
	jp	z,ps_track_loop
	cp	endloop
	jp	z,ps_track_endloop
	cp	call
	jp	z,ps_track_call
	cp	return
	jp	z,ps_track_return
	cp	goto
	jp	z,ps_track_goto
	cp	instrument
	jp	z,ps_track_instrument
	cp	enddata
	jp	z,ps_track_enddata
	cp	mastervolume
	jp	z,ps_track_mastervolume
	cp	speed
	jp	z,ps_track_speed
	cp	transport
	jp	z,ps_track_trans

ps_note:bit	3,(ix+spc_sfx)
	jr	nz,ps_track_noise

	add	a,(ix+transpose)
	ld	(ix+not_num),a

	push	hl			;pointing to note length here

	and	127
	ld	l,a
	ld	h,0
	add	hl,hl
	ld	de,frequency_table
	add	hl,de
	ld	a,(hl)
	inc	hl
	ld	(ix+phase_1_lo),a
	ld	(ix+phase_2_lo),a
	ld	(ix+freq_lo),a
	ld	a,(hl)
	ld	(ix+phase_1_hi),a
	ld	(ix+phase_2_hi),a
	ld	(ix+freq_hi),a

	pop	hl			;retrieve pointer to note length

	ld	de,0
	ld	e,(hl)			;one byte note length
	inc	hl
	ld	a,e
	rlca
	jr	nc,end_length
	ld	d,(hl)			;two byte note length
	inc	hl
	or	a
	rr	d
	rra
	ld	e,a
end_length:

	ld	(ix+trk_dat_lo),l
	ld	(ix+trk_dat_hi),h

	ld	hl,0
	ld	b,(ix+trk_spd)
ps_track_add_length:
	add	hl,de
	djnz	ps_track_add_length

	ld	(ix+not_ctr_lo),l
	ld	(ix+not_ctr_hi),h


	ld	l,(ix+cur_ins_lo)
	ld	h,(ix+cur_ins_hi)
	ld	a,(hl)
	inc	hl
	ld	(ix+spc_sfx),a
	ld	a,(hl)
	inc	hl
	ld	(ix+sfx_ptr_lo),a
	ld	a,(hl)
	inc	hl
	ld	(ix+sfx_ptr_hi),a
	ld	a,(hl)
	inc	hl
	ld	(ix+vol_dat_lo),a
	ld	a,(hl)
	ld	(ix+vol_dat_hi),a
	jp	ps_get_special_fx

ps_track_noise:
	ld	de,0
	ld	e,(hl)			;one byte note length
	inc	hl
	ld	a,e
	rlca
	jr	nc,end_length_noise
	ld	d,(hl)			;two byte note length
	inc	hl
	or	a
	rr	d
	rra
	ld	e,a
end_length_noise:

	ld	(ix+trk_dat_lo),l
	ld	(ix+trk_dat_hi),h

	ld	hl,0
	ld	b,(ix+trk_spd)
ps_track_noise_add_length:
	add	hl,de
	djnz	ps_track_noise_add_length

	ld	(ix+not_ctr_lo),l
	ld	(ix+not_ctr_hi),h


	ld	l,(ix+cur_ins_lo)
	ld	h,(ix+cur_ins_hi)

	ld	a,(hl)
	inc	hl
	ld	(ix+spc_sfx),a
	ld	a,(hl)
	inc	hl
	ld	(ix+sfx_ptr_lo),a
	ld	a,(hl)
	inc	hl
	ld	(ix+sfx_ptr_hi),a
	ld	a,(hl)
	inc	hl
	ld	(ix+vol_dat_lo),a
	ld	a,(hl)
	ld	(ix+vol_dat_hi),a
	jp	ps_get_special_fx

ps_track_goto:
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	jp	ps_track_get_command

ps_track_enddata:
	xor	a
	ld	(ix+trk_dat_lo),a
	ld	(ix+trk_dat_hi),a
	jp	ps_finish

ps_track_instrument:
	ld	a,(hl)
	inc	hl
	push	hl
	ld	l,a
	cp	0ffh
	jr	nz,nrand
	ld	a,r
	and	31
	ld	l,a
	sub	21
	jr	c,nrand
	ld	l,a
nrand:
	ld	h,0
	add	hl,hl
	ld	de,instrument_table
	add	hl,de
	ld	a,(hl)
	inc	hl
	ld	(ix+cur_ins_lo),a
	ld	a,(hl)
	ld	(ix+cur_ins_hi),a
	pop	hl
	jp	ps_track_get_command

ps_track_call:
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(ix+trk_stk_lo)
	ld	d,(ix+trk_stk_hi)
	ex	de,hl	;de=current address, hl=stack address
	dec	hl
	ld	(hl),d
	dec	hl
	ld	(hl),e
	ex	de,hl	;de=stack address, hl=current address
	ld	(ix+trk_stk_lo),e
	ld	(ix+trk_stk_hi),d
	ld	l,c
	ld	h,b
	jp	ps_track_get_command

ps_track_return:
	ld	l,(ix+trk_stk_lo)
	ld	h,(ix+trk_stk_hi)
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	inc	hl
	ld	(ix+trk_stk_lo),l
	ld	(ix+trk_stk_hi),h
	ld	l,e
	ld	h,d
	jp	ps_track_get_command

ps_track_loop:
	ld	e,(ix+trk_stk_lo)
	ld	d,(ix+trk_stk_hi)
	ld	a,(hl)
	inc	hl
	ex	de,hl
	dec	hl
	ld	(hl),d
	dec	hl
	ld	(hl),e
	dec	hl
	ld	(hl),a
	ex	de,hl
	ld	(ix+trk_stk_lo),e
	ld	(ix+trk_stk_hi),d
	jp	ps_track_get_command

ps_track_endloop:
	ld	e,(ix+trk_stk_lo)
	ld	d,(ix+trk_stk_hi)
	ld	a,(de)
	dec	a
	jr	z,ps_track_end_of_loop
	ld	(de),a
	ex	de,hl
	inc	hl
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	jp	ps_track_get_command

ps_track_end_of_loop:
	inc	de
	inc	de
	inc	de
	ld	(ix+trk_stk_lo),e
	ld	(ix+trk_stk_hi),d
	jp	ps_track_get_command

ps_track_pause:
	ld	de,0
	ld	e,(hl)			;one byte note length
	inc	hl
	ld	a,e
	rlca
	jr	nc,end_length_pause
	ld	d,(hl)			;two byte note length
	inc	hl
	or	a
	rr	d
	rra
	ld	e,a
end_length_pause:

	ld	(ix+trk_dat_lo),l
	ld	(ix+trk_dat_hi),h

	ld	(ix+not_num),127

	ld	hl,0
	ld	b,(ix+trk_spd)
ps_track_pause_add_length:
	add	hl,de
	djnz	ps_track_pause_add_length

	ld	(ix+not_ctr_lo),l
	ld	(ix+not_ctr_hi),h

	ld	(ix+spc_sfx),16
	jp	ps_end

ps_track_mastervolume:
	ld	de,master_volume_data
	ldi		;start volume
	ldi		;volume add
	ldi		;speed
	ld	a,1
	ld	(de),a	;speed counter
	jp	ps_track_get_command

ps_track_speed:
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_spd),a
	jp	ps_track_get_command

ps_track_trans:
	ld	a,(hl)
	inc	hl
	ld	(ix+transpose),a
	jp	ps_track_get_command

;volume

ps_volume:
	ld	l,(ix+vol_dat_lo)
	ld	h,(ix+vol_dat_hi)
	ld	a,l
	or	h
	jr	z,ps_end

ps_vol_get_command:
	ld	a,(hl)
	inc	hl
	cp	goto
	jr	z,ps_vol_goto
	cp	enddata
	jr	z,ps_vol_enddata
	ld	(ix+vol_dat_lo),l
	ld	(ix+vol_dat_hi),h
	ld	(ix+volume),a
	jp	ps_end

ps_vol_enddata:
	xor	a
	ld	(ix+vol_dat_lo),a
	ld	(ix+vol_dat_hi),a
	jp	ps_end

ps_vol_goto:
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	jp	ps_vol_get_command



;end

ps_track_off:
	ld	a,(ix+sfx_ctr)
	or	a
	jp	z,ps_volume_zero
	dec	(ix+sfx_ctr)
	ret

ps_end:	ld	a,(ix+sfx_ctr)
	or	a
	jr	z,ps_music

ps_fx:	dec	(ix+sfx_ctr)
	ret

ps_music:
	bit	4,(ix+spc_sfx)
	jr	z,ps_music_tst_3
	ld	a,(ix+chan_off)
	out	(psg),a
	ret

ps_music_tst_3:
	bit	3,(ix+spc_sfx)
	jr	nz,ps_music_noise
	ld	a,(ix+freq_lo)	;set frequency
	ld	l,a
	ld	h,(ix+freq_hi)
	and	0fh
	or	(ix+freq_bits)
	out	(psg),a
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	ld	a,h
	and	00111111b
	out	(psg),a
	jp	ps_set_volume

ps_music_noise:
	ld	a,(ix+freq_bits)
	or	a
	jr	z,ps_set_volume
	out	(psg),a

ps_set_volume:
	ld	a,(master_volume_data)
	or	a
	jr	z,ps_volume_zero
	cp	16
	jr	z,ps_volume_max

	ld	b,a
	ld	c,(ix+volume)
	xor	a
ps_volume_add:
	add	a,c
	djnz	ps_volume_add
	srl	a
	srl	a
	srl	a
	srl	a
	jp	ps_write_volume

ps_volume_zero:
	xor	a
	jp	ps_write_volume

ps_volume_max:
	ld	a,(ix+volume)	;set volume

ps_write_volume:
	xor	0fh
	or	(ix+vol_bits)
	out	(psg),a

ps_finish:
	ret



;////// INIT CHANNELS //////

init_channels:
	dec	a
	ld	l,a
	ld	h,0
	add	hl,hl
	ld	a,(MusicSpeed)
	ld	de,music_ptrs
	cp	1
	jr	nz,NotSlow
	ld	de,SlowMusic
NotSlow:
	add	hl,de
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a

schip:
	exx
	ld	hl,chan_0+not_num
	ld	de,chan_0+not_ctr_lo
	ld	bc,4*(32+StackSize)-1
	ld	(hl),0
	ldir
	ld	hl,chan_0+26
	ld	(hl),080h	;freq bits
	inc	hl
	ld	(hl),090h	;vol bits
	inc	hl
	ld	(hl),09fh	;chan off bits
	ld	hl,chan_1+26
	ld	(hl),0a0h
	inc	hl
	ld	(hl),0b0h
	inc	hl
	ld	(hl),0bfh
	ld	hl,chan_2+26
	ld	(hl),0c0h
	inc	hl
	ld	(hl),0d0h
	inc	hl
	ld	(hl),0dfh
	ld	hl,noise_chan+27
	ld	(hl),0f0h
	inc	hl
	ld	(hl),0ffh
	exx

	ld	ix,chan_0		;init channel 0
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_dat_lo),a
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_dat_hi),a
	ld	de,chan_0_stack+StackSize
	ld	(ix+trk_stk_lo),e
	ld	(ix+trk_stk_hi),d
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_spd),a
	ld	a,(hl)
	inc	hl
	ld	(ix+transpose),a

	ld	ix,chan_1		;init channel 1
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_dat_lo),a
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_dat_hi),a
	ld	de,chan_1_stack+StackSize
	ld	(ix+trk_stk_lo),e
	ld	(ix+trk_stk_hi),d
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_spd),a
	ld	a,(hl)
	inc	hl
	ld	(ix+transpose),a

	ld	ix,chan_2		;init channel 2
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_dat_lo),a
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_dat_hi),a
	ld	de,chan_2_stack+StackSize
	ld	(ix+trk_stk_lo),e
	ld	(ix+trk_stk_hi),d
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_spd),a
	ld	a,(hl)
	inc	hl
	ld	(ix+transpose),a

	ld	ix,noise_chan		;init noise channel
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_dat_lo),a
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_dat_hi),a
	ld	de,noise_stack+StackSize
	ld	(ix+trk_stk_lo),e
	ld	(ix+trk_stk_hi),d
	ld	a,(hl)
	inc	hl
	ld	(ix+trk_spd),a

	ld	de,master_volume_data	;init master volume data
	ldi
	ldi
	ldi
	ld	a,1
	ld	(de),a
	ret


;////// SOUND FX SUBROUTINE //////


sfx_dat_lo	equ	0
sfx_dat_hi	equ	1
sfx_stk_lo	equ	2
sfx_stk_hi	equ	3
sfx_spd		equ	4
sfx_not_num	equ	5
sfx_not_ctr	equ	6
sfx_vol_dat_lo	equ	7
sfx_vol_dat_hi	equ	8
sfx_freq_lo	equ	9
sfx_freq_hi	equ	10
sfx_volume	equ	11
sfx_freq_bits	equ	12
sfx_vol_bits	equ	13




sfx_subroutine:
	ld	hl,(sfx_chan)
	ld	a,l
	or	h
	ret	z

	ld	ix,sfx_chan
	ld	a,(ix+sfx_not_ctr)
	or	a		;check zero (first time routine is called)
	jp	z,sf_track_get_command
	dec	a
	jp	z,sf_track_get_command
	ld	(ix+sfx_not_ctr),a
	jp	sf_volume



;track commands

sf_track_get_command:
	ld	a,(hl)
	inc	hl

	bit	7,a
	jp	z,sf_note
	cp	192
	jp	nc,sf_note

	cp	noteadd
	jp	z,sf_track_noteadd
	cp	freqadd
	jp	z,sf_track_freqadd
	cp	no_op
	jp	z,sf_track_no_op
	cp	loop
	jp	z,sf_track_loop
	cp	endloop
	jp	z,sf_track_endloop
	cp	call
	jp	z,sf_track_call
	cp	return
	jp	z,sf_track_return
	cp	use_chan3
	jp	z,sf_track_use_chan3
	cp	use_noise
	jp	z,sf_track_use_noise
	cp	use_chan3_and_noise
	jp	z,sf_track_use_chan3_and_noise
	cp	goto
	jr	z,sf_track_goto
	cp	enddata
	jr	z,sf_track_enddata
	cp	speed
	jp	z,sf_track_speed

	add	a,64		;a=periodic_highpitch-chan3_pitch
	out	(psg),a
	jp	sf_track_get_command



sf_note:ld	(ix+sfx_not_num),a
	ld	c,(hl)
	inc	hl
	ld	(ix+sfx_dat_lo),l
	ld	(ix+sfx_dat_hi),h

	and	127
	ld	l,a
	ld	h,0
	add	hl,hl
	ld	de,frequency_table
	add	hl,de
	ld	a,(hl)
	inc	hl
	ld	(ix+sfx_freq_lo),a
	ld	a,(hl)
	ld	(ix+sfx_freq_hi),a
sf_track_calculate_length:
	xor	a
	ld	b,(ix+sfx_spd)
sf_track_add_length:
	add	a,c
	djnz	sf_track_add_length
	ld	(ix+sfx_not_ctr),a
sf_track_write_frequency:
	ld	a,(ix+sfx_freq_lo)	;set frequency
	ld	l,a
	ld	h,(ix+sfx_freq_hi)
	and	0fh
	or	(ix+sfx_freq_bits)
	out	(psg),a
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,hl
	ld	a,h
	and	00111111b
	out	(psg),a
	jp	sf_volume

sf_track_goto:
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	jp	sf_track_get_command

sf_track_enddata:
	xor	a
	ld	(ix+sfx_dat_lo),a
	ld	(ix+sfx_dat_hi),a
	ld	(chan_2),a
	ld	(noise_chan),a
	ld	a,0dfh
	out	(psg),a
	ld	a,0ffh
	out	(psg),a
	ret

sf_track_call:
	ld	c,(hl)
	inc	hl
	ld	b,(hl)
	inc	hl
	ld	e,(ix+sfx_stk_lo)
	ld	d,(ix+sfx_stk_hi)
	ex	de,hl	;de=current address, hl=stack address
	dec	hl
	ld	(hl),d
	dec	hl
	ld	(hl),e
	ex	de,hl	;de=stack address, hl=current address
	ld	(ix+sfx_stk_lo),e
	ld	(ix+sfx_stk_hi),d
	ld	l,c
	ld	h,b
	jp	sf_track_get_command

sf_track_return:
	ld	l,(ix+sfx_stk_lo)
	ld	h,(ix+sfx_stk_hi)
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	inc	hl
	ld	(ix+sfx_stk_lo),l
	ld	(ix+sfx_stk_hi),h
	ld	l,e
	ld	h,d
	jp	sf_track_get_command

sf_track_loop:
	ld	e,(ix+sfx_stk_lo)
	ld	d,(ix+sfx_stk_hi)
	ld	a,(hl)
	inc	hl
	ex	de,hl
	dec	hl
	ld	(hl),d
	dec	hl
	ld	(hl),e
	dec	hl
	ld	(hl),a
	ex	de,hl
	ld	(ix+sfx_stk_lo),e
	ld	(ix+sfx_stk_hi),d
	jp	sf_track_get_command

sf_track_endloop:
	ld	e,(ix+sfx_stk_lo)
	ld	d,(ix+sfx_stk_hi)
	ld	a,(de)
	dec	a
	jr	z,sf_track_end_of_loop
	ld	(de),a
	ex	de,hl
	inc	hl
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	jp	sf_track_get_command

sf_track_end_of_loop:
	inc	de
	inc	de
	inc	de
	ld	(ix+sfx_stk_lo),e
	ld	(ix+sfx_stk_hi),d
	jp	sf_track_get_command

sf_track_noteadd:
	ld	a,(hl)
	inc	hl
	add	a,(ix+sfx_not_num)
	jp	sf_note

sf_track_freqadd:
	ld	e,(hl)
	inc	hl
	ld	d,(hl)
	inc	hl
	push	hl
	ld	l,(ix+sfx_freq_lo)
	ld	h,(ix+sfx_freq_hi)
	add	hl,de
	ld	(ix+sfx_freq_lo),l
	ld	(ix+sfx_freq_hi),h
	pop	hl
	ld	c,(hl)
	inc	hl
	ld	(ix+sfx_dat_lo),l
	ld	(ix+sfx_dat_hi),h
	jp	sf_track_calculate_length

sf_track_no_op:
	ld	c,(hl)
	inc	hl
	ld	(ix+sfx_dat_lo),l
	ld	(ix+sfx_dat_hi),h
	xor	a
	ld	b,(ix+sfx_spd)
sf_track_no_op_add_length:
	add	a,c
	djnz	sf_track_no_op_add_length
	ld	(ix+sfx_not_ctr),a
	jp	sf_volume

sf_track_speed:
	ld	a,(hl)
	inc	hl
	ld	(ix+sfx_spd),a
	jp	sf_track_get_command

sf_track_use_chan3:
	ld	a,(hl)
	inc	hl
	ld	(chan_2),a
	ld	a,0dfh
	out	(psg),a
	ld	a,0c0h
	ld	(ix+sfx_freq_bits),a
	ld	a,0d0h
	ld	(ix+sfx_vol_bits),a
	jp	sf_track_get_command

sf_track_use_noise:
	ld	a,(hl)
	inc	hl
	ld	(noise_chan),a
	ld	a,0ffh
	out	(psg),a
	xor	a
	ld	(ix+sfx_freq_bits),a
	ld	a,0f0h
	ld	(ix+sfx_vol_bits),a
	jp	sf_track_get_command

sf_track_use_chan3_and_noise:
	ld	a,(hl)
	inc	hl
	ld	(chan_2),a
	ld	(noise_chan),a
	ld	a,0dfh
	out	(psg),a
	ld	a,0ffh
	out	(psg),a
	ld	a,0c0h
	ld	(ix+sfx_freq_bits),a
	ld	a,0f0h
	ld	(ix+sfx_vol_bits),a
	ld	a,0e7h
	out	(psg),a
	jp	sf_track_get_command



;volume

sf_volume:
	ld	l,(ix+sfx_vol_dat_lo)
	ld	h,(ix+sfx_vol_dat_hi)
	ld	a,l
	or	h
	jr	z,sf_end

sf_vol_get_command:
	ld	a,(hl)
	inc	hl
	cp	goto
	jr	z,sf_vol_goto
	cp	enddata
	jr	z,sf_vol_enddata
	ld	(ix+sfx_vol_dat_lo),l
	ld	(ix+sfx_vol_dat_hi),h
	ld	(ix+sfx_volume),a
	jp	sf_end

sf_vol_enddata:
	xor	a
	ld	(ix+sfx_vol_dat_lo),a
	ld	(ix+sfx_vol_dat_hi),a
	jp	sf_end

sf_vol_goto:
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	jp	sf_vol_get_command



sf_end:	ld	a,(ix+sfx_volume)	;set volume
	xor	0fh
	or	(ix+sfx_vol_bits)
	out	(psg),a

	ret



init_sfx:
	dec	a
	ld	l,a
	ld	h,0
	add	hl,hl
	ld	de,sfx_ptrs
	add	hl,de
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a

	exx
	ld	hl,sfx_chan
	ld	de,sfx_chan+sfx_dat_hi
	ld	bc,32-1
	ld	(hl),0
	ldir
	exx

	ld	ix,sfx_chan
	ld	a,(hl)
	inc	hl
	ld	(ix+sfx_dat_lo),a
	ld	a,(hl)
	inc	hl
	ld	(ix+sfx_dat_hi),a
	ld	a,(hl)
	inc	hl
	ld	(ix+sfx_vol_dat_lo),a
	ld	a,(hl)
	inc	hl
	ld	(ix+sfx_vol_dat_hi),a
	ld	a,(hl)
	inc	hl
	ld	(ix+sfx_spd),a
	ld	hl,sfx_stack+StackSize
	ld	(sfx_chan+sfx_stk_lo),hl
	ret

;**************************************************************************
;----------------------------------------------------------------
;	Track Commands
;----------------------------------------------------------------
;
;	b,b	x,x (note,length)
;	b,b	speed,x
;	b,w	call,x
;	b,w	goto,x
;	b	return
;	b	enddata
;	b,b	instrument,x
;	b,b	loop,x
;	b	endloop
;	b,b,b,b	mastervolume,x,x,x (start volume, volume add, speed)
;
;----------------------------------------------------------------



;----------------------------------------------------------------
;	Sound FX Commands
;----------------------------------------------------------------
;
;	b,b	x,x		(note,length)
;	b,b	noteadd,x	(add x to current note)
;	b,b	freqadd,x	(add x to frequency)
;	b,b	no_op,x		(no operation)
;
;	b	periodic_highpitch
;	b	periodic_medpitch
;	b	periodic_lowpitch
;	b	white_highpitch
;	b	white_medpitch
;	b	white_lowpitch
;	b	chan3pitch (use channel 3 to generate frequency)
;	b,b	speed,x
;	b,w	call,x
;	b,w	goto,x
;	b	return
;	b	enddata
;	b,b	loop,x
;	b	endloop
;
;	b,b	use_chan3,x	(use channel 3 x frames)
;	b,b	use_noise,x	(use noise channel x frames)
;	b,b	use_chan3_and_noise,x
;
;----------------------------------------------------------------



;----------------------------------------------------------------
;	Arpeggio Commands
;----------------------------------------------------------------
;
;	b	x (note add value)
;	b,w	goto,x
;	b	enddata
;
;----------------------------------------------------------------



;----------------------------------------------------------------
;	Vibrato Commands
;----------------------------------------------------------------
;
;	b	x (vibrato add)
;	b,w	goto,x
;	b	enddata
;
;----------------------------------------------------------------



;----------------------------------------------------------------
;	Volume Commands
;----------------------------------------------------------------
;
;	b	x (volume)
;	b,w	goto,x
;	b	enddata
;
;----------------------------------------------------------------



;----------------------------------------------------------------
;	Noise Commands
;----------------------------------------------------------------
;
;	b	periodic_highpitch
;	b	periodic_medpitch
;	b	periodic_lowpitch
;	b	white_highpitch
;	b	white_medpitch
;	b	white_lowpitch
;	b	chan3pitch (use channel 3 to generate frequency)
;	b	0 (no operation)
;	b,w	goto,x
;	b	enddata
;
;----------------------------------------------------------------



;----------------------------------------------------------------
;	Init Data Structure
;----------------------------------------------------------------
;
;	w	track #0 data address
;	b	speed
;	b	transpose
;
;	w	track #1 data address
;	b	speed
;	b	transpose
;
;	w	track #2 data address
;	b	speed
;	b	transpose
;
;	w	noise address
;	b	speed
;
;	b	start volume
;	b	volume add
;	b	speed
;
;----------------------------------------------------------------



;----------------------------------------------------------------
;	Instrument Header
;----------------------------------------------------------------
;
;	b	special fx (0=off,1=arpeggio,2=phase,4=vibrato,8=noise)
;	w	arpeggio/noise/vibrato/phase speed data
;	w	volume data address
;
;----------------------------------------------------------------



;----------------------------------------------------------------
;	Instrument Table Structure
;----------------------------------------------------------------
;
;	w	instrument 0 address
;	w	instrument 1 address
;	w	instrument 2 address
;	w	.
;	w	.
;	w	.
;	w	instrument x address
;
;----------------------------------------------------------------



;----------------------------------------------------------------
;	Sound FX Header
;----------------------------------------------------------------
;
;	w	sound fx data address
;	w	volume data address
;	b	speed
;
;----------------------------------------------------------------


;sound commands

speed		equ	128
call		equ	129
goto		equ	130
return		equ	131
enddata		equ	132
instrument	equ	133
loop		equ	134
endloop		equ	135
pause		equ	136
mastervolume	equ	137
transport	equ	138

arpeggio	equ	1
phase		equ	2
vibrato		equ	4
noise		equ	8

waz		equ	32


periodic_highpitch	equ	0+0e0h-64
periodic_medpitch	equ	1+0e0h-64
periodic_lowpitch	equ	2+0e0h-64

white_highpitch		equ	4+0e0h-64
white_medpitch		equ	5+0e0h-64
white_lowpitch		equ	6+0e0h-64

chan3pitch		equ	7+0e0h-64



noteadd			equ	139
freqadd			equ	140
no_op			equ	141
use_chan3		equ	142
use_noise		equ	143
use_chan3_and_noise	equ	144



;////// INSTRUMENT SECTION //////

;instrument pointers

Instrument_table:
	dw	PianoLong	;0
	dw	sustainer	;1
	dw	vibrator 	;2
	dw	ramper		;3

	;.............................

	dw	bass		;4
	dw	WarbleShortB	;5
	dw	WarbleShortA	;6
	dw	ramp_down_fast	;7
	dw	nifty		;8
	dw	hushy		;9
	dw	offty		;10
	dw	SlowToneA	;11
	dw	SlowToneB	;12
	dw	waveform_med	;13
	dw	softy		;14
	dw	pling		;15
	dw	Bleep		;16
	dw	SubBass		;17
	dw	EchoTone	;18
	dw	flute;down_24		;19
	dw	PianoShort	;20

;percussion section:

	dw	hi_hat		;21
	dw	cymbal		;22
	dw	bass_drum	;23
	dw	drum2		;24
	dw	symdrum		;25
	dw	drum1		;26
	dw	bass_drum2	;27
	dw	tom1		;28
	dw	tom2		;29
	dw	cymbal2		;30

;-----------------------------------------------------------------
;instrument definitions


PianoLong:
	db	0		;special fx
	dw	0		;vibrato address
	dw	piano_volume1	;volume address

PianoShort:
	db	0		;special fx
	dw	0		;vibrato address
	dw	piano_volume2	;volume address

Sustainer:
	db	0		;special fx
	dw	0		;vibrato address
	dw	bass_volume	;volume address

Vibrator:
	db	vibrato		;special fx
	dw	flute_vibrato	;vibrato address
	dw	flute_volume	;volume address

Ramper:
	db	waz		;special fx
	dw	waz_dat		;vibrato address
	dw	bass_volume	;volume address

;-----------------------------------------------------------------

Piano:	db	waz;0		;special fx
	dw	waz_dat0;0		;vibrato address
	dw	piano_volume1	;volume address

Piano_vibrato:
	db	waz		;special fx
	dw	waz_dat1	;vibrato address
	dw	piano_volume1	;volume address

Phaser:	db	0		;special fx
	dw	0		;phase speed
	dw	bass_volume	;volume address

hushy:	db	0		;special fx
	dw	0		;phase speed
	dw	soft_volume	;volume address

Flute:	db	vibrato		;special fx
	dw	flute_vibrato	;vibrato address
	dw	flute_volume	;volume address

offty:	db	waz		;special fx
	dw	waz4		;vibrato address
	dw	flute_volume	;volume address

Bass:	db	0		;special fx
	dw	0		;vibrato address
	dw	bass_volume	;volume address

WarbleShortA:
	db	waz			;special fx
	dw	waz_dat6		;vibrato address
	dw	ramp_down_fast_volume	;volume address

WarbleShortB:
	db	waz			;special fx
	dw	Waz_Dat5		;vibrato address
	dw	ramp_down_fast_volume	;volume address

SlowToneA:
	db	waz			;special fx
	dw	waz_dat7		;vibrato address
	dw	ramp_down_slow_volume	;volume address

SlowToneB:
	db	waz			;special fx
	dw	waz_dat8		;vibrato address
	dw	ramp_down_slow_volume	;volume address

EchoTone:
	db	0			;special fx
	dw	0			;arpeggio address
	dw	EchoVolume		;volume address

SubBass:
	db	arpeggio			;special fx
	dw	SubArpeggio		;arpeggio address
	dw	SubVolume		;volume address

Bleep:
	db	waz			;special fx
	dw	waz_dat9		;arpeggio address
	dw	BleepVolume		;volume address


hi_hat:
	db	noise		;special fx
	dw	perc_0_noise	;arpeggio address/noise address
	dw	perc_0_volume	;volume address

cymbal:
	db	noise		;special fx
	dw	perc_1_noise	;arpeggio address/noise address
	dw	perc_1_volume	;volume address

cymbal2:
	db	noise		;special fx
	dw	perc_1_noise	;arpeggio address/noise address
	dw	perc_3_volume	;volume address

bass_drum:
	db	noise		;special fx
	dw	perc_2_noise	;arpeggio address/noise address
	dw	perc_2_volume	;volume address

drum2:
	db	noise		;special fx
	dw	drum_noise	;arpeggio address/noise address
	dw	drum2_volume	;volume address

symdrum:
	db	noise		;special fx
	dw	perc_4_noise	;arpeggio address/noise address
	dw	perc_0_volume	;volume address

drum1:
	db	noise		;special fx
	dw	drum_noise	;arpeggio address/noise address
	dw	drum1_volume	;volume address

bass_drum2:
	db	noise		;special fx
	dw	perc_5_noise	;arpeggio address/noise address
	dw	perc_2_volume	;volume address

tom1:
	db	noise		;special fx
	dw	perc_6_noise	;arpeggio address/noise address
	dw	perc_2_volume	;volume address
tom2:
	db	noise		;special fx
	dw	perc_7_noise	;arpeggio address/noise address
	dw	perc_2_volume	;volume address



Ramp_down_slow:
	db	vibrato			;special fx
	dw	ramp_vibrato		;vibrato address
	dw	ramp_down_slow_volume	;volume address

Ramp_down_med:
	db	vibrato	    		;special fx
	dw	ramp_vibrato		;vibrato address
	dw	ramp_down_med_volume	;volume address

Ramp_down_fast:
	db	vibrato			;special fx
	dw	ramp_vibrato		;vibrato address
	dw	ramp_down_slow_volume	;volume address

nifty:
	db	waz			;special fx
	dw	waz_dat3		;vibrato address
	dw	bass_volume		;volume address

Ramp_up_med:
	db	vibrato			;special fx
	dw	ramp_vibrato		;vibrato address
	dw	ramp_up_med_volume	;volume address

Ramp_up_fast:
	db	vibrato			;special fx
	dw	ramp_vibrato		;vibrato address
	dw	ramp_up_fast_volume	;volume address

Waveform_full:
	db	vibrato		;special fx
	dw	full_med_low_vibrato	;vibrato address
	dw	full_volume	;volume address

Waveform_med:
	db	waz;vibrato		;special fx
	dw	waz_dat2;full_med_low_vibrato	;vibrato address
	dw	med_volume	;volume address

Waveform_low:
	db	waz;vibrato		;special fx
	dw	waz_dat2;full_med_low_vibrato	;vibrato address
	dw	low_volume	;volume address

softy:	db	waz		;special fx
	dw	waz_dat2	;phase speed
	dw	soft_volume	;volume address

Pling:	db	arpeggio	;special fx
	dw	pling_arpeggio	;arpeggio address
	dw	perc_0_volume	;volume address

Chime:	db	vibrato		;special fx
	dw	piano_vibrato_data	;vibrato address
	dw	chime_volume	;volume address

Siren:	db	arpeggio	;special fx
	dw	siren_arpeggio	;arpeggio address
	dw	full_volume	;volume address

Telephone:
	db	arpeggio		;special fx
	dw	telephone_arpeggio	;arpeggio address
	dw	telephone_volume	;volume address

Up_24:	db	arpeggio		;special fx
	dw	up_24_arpeggio		;arpeggio address
	dw	up_down_24_volume	;volume address

Down_24:db	arpeggio		;special fx
	dw	down_24_arpeggio	;arpeggio address
	dw	up_down_24_volume	;volume address

;arpeggio definitions

SubArpeggio:
	db	-12
	db	EndData

Pling_arpeggio:
	db	12,-12,enddata

Siren_arpeggio:
	db	1,1,1,1,1,1,1,1,1,1,1,1
	db	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
	db	goto
	dw	   siren_arpeggio

Telephone_arpeggio:
	db	12,-12
	db	goto
	dw	   telephone_arpeggio

Up_24_arpeggio:
	db	0,6,6,6,6,enddata

Down_24_arpeggio:
	db	0,-6,-6,-6,-6,enddata


;vibrato definitions

Piano_vibrato_data:
	db	0,0,0,0
	db	-1,1,1,-1
	db	-2,2,2,-2
	db	-3,3,3,-3
pv_rep:	db	-4,-4,4,4,4,4,-4,-4
	db	goto
	dw	   pv_rep

Flute_vibrato:
	db	0,0,0,2
fv_rep:	db	-3,-2,2,-1,3,2,-2,1
	db	goto
	dw	   fv_rep

Ramp_vibrato:
	db	0
rv_rep:	db	-1,1,1,-1
	db	goto
	dw	   rv_rep

Full_med_low_vibrato:
	db	0
fml_rep:db	-2,2,2,-2
	db	goto
	dw	   fml_rep

waz_dat:
	db	0,-1,1,1
	db	goto
	dw		Waz_Dat

waz_dat0:
	db	-5,5,0
	db	goto
	dw	 waz_dat0

waz_dat1:
	db	-1,1,0,-2,2,0,-4,4,0,-8,8,0
	db	goto
	dw	 waz_dat1


waz_dat2:
	db	0,-1
waz2:
	db	-1,1,1,-1
	db	goto
	dw	waz2

waz_dat3:
	db	2,1,-1,-2
waz3:
	db	-1
	db	goto
	dw	waz3

waz4:
	db	-2
nuz:
	db	0
	db	goto
	dw	nuz

Waz_Dat6:
	db	6
	db	goto
	dw		Waz_Dat56
Waz_Dat5:
	db	-6
Waz_Dat56:
	db	0,1,-1,0,2,-2,0,4,-4,0,2,-2,0,1,-1
	db	goto
	dw		Waz_Dat56

waz_dat8:
	db	1
waz_dat7:
	db	0
	db	goto
	dw		waz_dat7

waz_dat9:
	db	0,-1
	db	goto
	dw		waz_dat9

;volume definitions
Piano_volume1:
	db	13,14,15,15,15,14,13,12,12,12,12
	db	enddata
Piano_volume2:
	db	13,14,15,15,15,14,13,12,12,12,12
	db	11,10,9,8,7,6,5,4,3,2,1,0
	db	enddata


Phaser_volume:
	db	1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,enddata

Flute_volume:
	db	11,12,13,14,15,14,13,12,11,10,9,enddata

Bass_volume:
	db	15,15,15,15,14,14,14,13,12,9,enddata
	;7,6,6,5,5,4,3,2,1,1,0,enddata

Perc_0_volume:
	db	15,15,14,12,8,6,4,0,enddata
Perc_1_volume:
	db	15,14,13,12,12,12,12,11,11,11,10,9,8,6,4,2,0,enddata
Perc_2_volume:
	db	14,15,15,14,13,12,10,8,6,2,0,enddata
soft_volume:
perc_3_volume:
	db	12,10,9,8,7,6,5,4,3,2
	db	0,enddata
drum1_volume:
	db	15,13,11,9,5,3,2,1
	db	0,enddata
drum2_volume:
	db	14,14,13,12,11,9,5
	db	0,enddata


Ramp_down_slow_volume:
	db	12,13,14,15,15
	db	15,15,15,15,15
	db	15,15,15,15,15
	db	15,15,14,14,13,13,12,12,11,11,10,10,9,9,8,8
	db	7,7,6,6,enddata

Ramp_down_med_volume:
	db	15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,enddata

Ramp_down_fast_volume:
	db	15,13,11,9,7,5,3,1,0,enddata

Ramp_up_slow_volume:
	db	1,1,2,2,3,3,4,4,5,5,6,6,7,7
	db	8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,enddata

Ramp_up_med_volume:
	db	1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,enddata

Ramp_up_fast_volume:
	db	1,3,5,7,9,11,13,15,enddata

Full_volume:
	db	15,enddata

Med_volume:
	db	11,enddata

Low_volume:
	db	7,enddata

Chime_volume:
	db	15,14,13,12,11,10,11,12,13,12,11,10,9,8
	db	9,10,11,10,9,8,7,6,7,8,9,8,7,6,5,4,5,6,7,6,5,4,3,2,3,4,5
	db	4,3,2,1,0,enddata

Telephone_volume:
	db	15,15,12,12,14,14,11,11
	db	15,15,12,12,14,14,11,11
	db	15,15,12,12,14,14,11,11
	db	15,15,12,12,14,14,11,11
	db	0
	db	enddata

Up_down_24_volume:
	db	15,13,11,9,7,0,enddata


EchoVolume:
	db	15,15,14,14,12,8,4,2
	db	8,8,7,7,6,3,2,1
	db	4,4,3,3,2,2,1,1
	db	2,2,2,2,1,1,1,1
	db	1,1,1,1,1,1,1,1
	db	0
	db	EndData
BleepVolume:
	db	15,15,15,15,14,12,0
	db	EndData
SubVolume:
	db	14,15,15,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
	db	EndData

;noise  definitions

Perc_0_noise:
	db	white_highpitch,0,0,0,0
	db	white_medpitch,0,0,0
	db	white_lowpitch
	db	enddata

Perc_1_noise:
	db	white_highpitch,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	enddata

Perc_2_noise:
	db	white_lowpitch,0,0,0,0,0,0,0,0,0,0
	db	enddata

Percusion_3_noise:
	db	white_highpitch,0
	db	white_lowpitch,0
	db	white_highpitch,0,0
	db	white_lowpitch,0,0
	db	white_medpitch,0,0,0
	db	enddata

Perc_4_noise:
	db	white_medpitch,0
	db	white_highpitch,0,0,0,0,0,0,0,0
	db	enddata
Perc_5_noise:
	db	white_medpitch,0,0,0,0,0,0,0,0,0,0
	db	enddata
Perc_6_noise:
	db	periodic_lowpitch,0,0,0,0,0,0,0,0,0,0
	db	enddata
Perc_7_noise:
	db	periodic_medpitch,0,0,0,0,0,0,0,0,0,0
	db	enddata




drum_noise:
	db	white_lowpitch,0
	db	white_medpitch,0,0
	db	white_highpitch,0,0,0,0,0,0
	db	enddata

;////// SOUND FX SECTION //////


sfx_ptrs:
	dw	sfx_1,sfx_2,sfx_3,sfx_4,sfx_5,sfx_6,sfx_7,sfx_8
	dw	sfx_9,sfx_10,sfx_11,sfx_12,sfx_13

;sound fx headers

sfx_1:				;icon select
	dw	sfx_1_data		;data address
	dw	sfx_1_volume	;volume address
	db	1			;speed

sfx_2:				;Icon Toggle
	dw	sfx_2_data		;data address
	dw	sfx_1_volume	;volume address
	db	1			;speed

sfx_3:				;Spidey Sense tingle
	dw	sfx_3_data		;data address
	dw	sfx_6_volume	;volume address
	db	2			;speed

sfx_4:				;Gunshot
	dw	sfx_4_data		;data address
	dw	sfx_4_volume	;volume address
	db	1			;speed

sfx_5:				;Claws In/Out
	dw	sfx_5_data		;data address
	dw	sfx_5_volume	;volume address
	db	1			;speed

sfx_6:				;lazer-fizz
	dw	sfx_6_data		;data address
	dw	sfx_6_volume	;volume address
	db	1			;speed

sfx_7:				;tin-fizz (lightning)
	dw	sfx_7_data		;data address
	dw	sfx_7_volume	;volume address
	db	1			;speed

sfx_8:				;Punch
	dw	sfx_8_data		;data address
	dw	sfx_8_volume	;volume address
	db	1			;speed

sfx_9:				;Kick
	dw	sfx_9_data		;data address
	dw	sfx_9_volume	;volume address
	db	1			;speed

sfx_10:				;land on ground
	dw	sfx_10_data		;data address
	dw	sfx_9_volume	;volume address
	db	1			;speed

sfx_11:
				;hit home
	dw	sfx_11_data	;data address
	dw	sfx_4_volume	;volume address
	db	1			;speed

sfx_12:
	;Show Hit In A BIG Way
	dw	sfx_12_data	;data address
	dw	sfx_12_volume	;volume address
	db	1			;speed

sfx_13:				;snowballs
	dw	sfx_13_data	;data address
	dw	sfx_13_volume	;volume address
	db	1			;speed


;sound fx data definitions

sfx_1_data:			;icon select
	db	use_chan3_and_noise,21
	db	20,1
	db	loop,15
	db	   noteadd,5,1
	db	endloop
	db	enddata

sfx_2_data:			;icon toggle
	db	use_chan3,16
	db	40,1
	db	loop,15

	db	freqadd
	dw		64
	db		1
	db	EndLoop
	db	enddata

sfx_3_data:			;spidey sense tingle
	db	use_chan3,40
	db	loop,20
	db	   60,1,36,1
	db	endloop
	db	enddata

sfx_4_data:			;gunshot
	db	use_chan3_and_noise,9
	db	24,1
	db	60,1
	db	loop,3
	db	   noteadd,-2,1
	db	   noteadd,-1,1
	db	endloop
	db	enddata

sfx_5_data:			;shoot web bolt/line
	db	use_chan3_and_noise,16
	db	21,1
	db	loop,15
	db	   noteadd,5,1
	db	endloop
	db	enddata

sfx_6_data:			;spidey hurt
	db	use_chan3_and_noise,21
	db	60,1
	db	loop,10
	db	   noteadd,8,1
	db	   noteadd,-10,1
	db	endloop
	db	enddata

sfx_7_data:			;lightning
	db	use_chan3_and_noise,16
	db	96,1
	db	loop,15
	db	   noteadd,-5,1
	db	endloop
	db	enddata

sfx_8_data:			;punch
	db	use_noise,9
	db	white_lowpitch,no_op,1
	db	white_medpitch,no_op,2
	db	white_highpitch,no_op,6
	db	enddata

sfx_9_data:			;kick
	db	use_noise,9
	db	white_medpitch,no_op,1
	db	white_lowpitch,no_op,2
	db	white_highpitch,no_op,6
	db	enddata

sfx_10_data:			;land
	db	use_chan3_and_noise,9
	db	23,1
	db	loop,8
	db	   noteadd,5,1
	db	endloop
	db	enddata

sfx_11_data:			;hit home
	db	use_chan3_and_noise,9
	db	63,1
	db	loop,8
	db	   noteadd,-5,1
	db	endloop
	db	enddata

sfx_12_data:			;Show Hit
	db	use_chan3_and_noise,20
	db	56,1
	db	120,1
	db	loop,15
	db	   noteadd,-4,1
	db	endloop
	db	44,1,22,1,0,1
	db	enddata

sfx_13_data:
	db	use_chan3_and_noise,20
	db	56,1
	db	120,1
	db	loop,15
	db	   noteadd,-4,1
	db	endloop
	db	44,1,22,1,0,1
	db	enddata


;sound fx volume definitions

sfx_1_volume:			;icon select
	db	12,12,13,13,14,14,15,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
	db	enddata

sfx_2_volume:			;icon toggle
	db	15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
	db	enddata

sfx_3_volume:			;spidey sense tingle
	db	6,7,8,9,10,11,12,13,14
	db	15,15,14,14,13,13,12,12,11,11
	db	10,10,9,9,8,8,7,7,6,6
	db	5,5,4,4,3,3,2,2,1,1
	db	0,enddata

sfx_4_volume:			;gunshot
	db	15,14,13,12,11,10,9,7,5,3,1
	db	0,enddata

sfx_5_volume:			;shoot web bolt/line
	db	1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
	db	0,enddata

sfx_6_volume:			;spidey hurt
	db	15,15,15,15,15,15,15,11,11,11,11,11,11,11,7,7,7,7,7,7,7
	db	0,enddata

sfx_7_volume:			;lightning
	db	15,14,13,12,11,10,9,8,7,6,5,4,3,2,1
	db	0,enddata

sfx_8_volume:			;punch
	db	15,13,11,9,5,3,2,1
	db	0,enddata

sfx_9_volume:			;kick
	db	9,11,13,15,14,13,11,7
	db	0,enddata

sfx_10_volume:			;
	db	14,15,14,13,12,11,10,9,8,7,6,5,4,5,3,2,1
	db	0,enddata

sfx_11_volume:			;
	db	14,15,14,13,12,11,10,9,8,7,6,5,4,5,3,2,1
	db	0,enddata

sfx_12_volume:			;stick
	db	14,15,14,13,12,11,10,9,8,7,6,5,4,5,3,2,1
	db	0,enddata

sfx_13_volume:			;
	db	14,15,14,13,12,11,10,9,8,7,6,5,4,5,3,2,1
	db	0,enddata



;////// BUFFERS, TABLES ETC //////

Frequency_table:
	DW	03F9H,03C0H,038AH,0357H,0327H,02FAH,02CFH,02A7H,0281H,025DH,023BH,021BH
	DW	01FCH,01E0H,01C5H,01ACH,0194H,017DH,0168H,0153H,0140H,012EH,011DH,010DH
	DW	00FEH,00F0H,00E2H,00D6H,00CAH,00BEH,00B4H,00AAH,00A0H,0097H,008FH,0087H
	DW	007FH,0078H,0071H,006BH,0065H,005FH,005AH,0055H,0050H,004CH,0047H,0043H
	; the rest here are probably only useful for noise
	DW	0040H,003CH,0039H,0035H,0032H,002FH,002DH,002AH,0028H,0026H,0023H,0021H
	DW	0020H,001EH,001CH,001AH,0019H,0017H,0016H,0015H,0014H,0013H,0011H,0010H
	DW	0010H,000FH,000EH,000DH,000DH,000CH,000BH,000BH,000AH,0009H,0009H,0008H
	DW	0008H,0007H,0007H,0007H,0006H,0006H,0006H,0005H,0005H,0005H,0004H,0004H
	DW	0004H,0003H,0003H,0003H,0003H,0003H,0003H,0002H,0002H,0002H,0002H,0002H
	DW	0002H,0001H,0001H,0001H,0001H,0001H,0001H,0001H,0001H,0001H,0001H,0001H
	DW	0001H,0000H,0000H,0000H,0000H,0000H,0000H,0000H

Vibrato_table:
	db	8,8,7,7,6,6,6,5,5,5,4,4
	db	4,4,4,3,3,3,3,3,3,2,2,2
	db	2,2,2,2,2,1,1,1,1,1,1,1
	db	1,1,1,1,1,1,1,1,1,1,1,1

	db	1,1,1,1,1,1,1,1,1,1,1,1		;use the rest for noise only!
	db	1,1,1,1,1,1,1,1,1,1,1,1
	db	1,1,1,1,1,1,1,1,1,1,1,1
	db	1,1,1,1,1,1,1,1,1,1,1,1


music_ptrs:
	dw	NOsong	;silence is golden!

	dw	song0;0	;0 Level1	2
					
	dw	song0;1	;1 Level2	3
					
	dw	song0;2	;2 Level3	4

	dw	song0;3	;3 Level4	5

	dw	song0;4	;4 Level5	6

	dw	song0;5	;5 Level6	7

	dw	song0;6	;6 Battle Tune	8
	dw	song0;7	;7 Win Tune	9
	dw	song0;8	;8 Loose Tune	10
	dw	song0;9	;9 Title Tune	11

SlowMusic:
	dw	NOsong	;silence is golden!

	dw	SlowSong0;0	;0 Level1	2
					
	dw	SlowSong0;1	;1 Level2	3
					
	dw	SlowSong0;2	;2 Level3	4

	dw	SlowSong0;3	;3 Level4	5

	dw	SlowSong0;4	;4 Level5	6

	dw	SlowSong0;5	;5 Level6	7

	dw	SlowSong0;6	;6 Battle Tune	8
	dw	SlowSong0;7	;7 Win Tune	9
	dw	SlowSong0;8	;8 Loose Tune	10
	dw	SlowSong0;9	;9 Title Tune	11


;null tune

NOsong:
	dw	null		;start address
	db	0		;speed
	db	0		;transpose

	dw	null		;start address
	db	0		;speed
	db	0		;transpose

	dw	null		;start address
	db	0		;speed
	db	0		;transpose

	dw	null		;start address
	db	0		;speed

	db	0		;start volume
	db	0		;volume add
	db	0		;speed

null:
	db	pause,1
	db	goto
	dw	null

hang64x5:
	db	pause,64
hang64x4:
	db	pause,64
hang64x3:
	db	pause,64
hang64x2:
	db	pause,64
hang64:
	db	pause,64
	db	return

Song0:
	dw	Channel0	;start address
	db	6		;speed
	db	-12		;transpose

	dw	Channel1	;start address
	db	6		;speed
	db	-12		;transpose

	dw	Channel2	;start address
	db	6		;speed
	db	-12		;transpose

	dw	Channel3	;start address
	db	6		;speed

	db	13		;start volume
	db	0		;volume add
	db	0		;speed

;MOD Title is:	renaissancegg      
Sample1	equ	4	;adamski2.raw        
Sample2	equ	21	;chahihat.raw        
Sample3	equ	0	;ahh.raw             
Sample4	equ	27	;drum7               
Sample5	equ	30	;19hat               
Sample6	equ	24	;tr909snare          
Sample7	equ	0	;bassdeep.raw        
Sample8	equ	1	;minor4              
Sample9	equ	9	;                    
Sample10	equ	10	
Sample11	equ	11	
Sample12	equ	12	
Sample13	equ	13	
Sample14	equ	14	
Sample15	equ	15	
Sample16	equ	16	
Sample17	equ	17	
Sample18	equ	18	
Sample19	equ	19	
Sample20	equ	20	
Sample21	equ	21	
Sample22	equ	22	
Sample23	equ	23	
Sample24	equ	24	
Sample25	equ	25	
Sample26	equ	26	
Sample27	equ	27	
Sample28	equ	28	
Sample29	equ	29	
Sample30	equ	30	
Sample31	equ	31	
;Skipping Byte = 7Fh
;Header Found = M.K.
;Number of Tracks=28
;Highest Track Number=28
Channel0:
	db	Loop,5
	db	call
	dw		Trk0Ch0		;0
	db	EndLoop
	db	call
	dw		Trk5Ch0		;5
	db	Loop,3
	db	call
	dw		Trk0Ch0		;6
	db	EndLoop
	db	call
	dw		Trk9Ch0		;9
	db	call
	dw		Trk10Ch0		;10
	db	Loop,5
	db	call
	dw		Trk11Ch0		;11
	db	EndLoop
	db	Loop,2
	db	call
	dw		Trk0Ch0		;16
	db	call
	dw		Trk5Ch0		;17
	db	call
	dw		Trk0Ch0		;18
	db	call
	dw		Trk0Ch0		;19
	db	EndLoop
	db	Loop,4
	db	call
	dw		Trk0Ch0		;24
	db	EndLoop
	db	goto
	dw		Channel0
Channel1:
	db	call
	dw		Trk0Ch1		;0
	db	call
	dw		Trk1Ch1		;1
	db	call
	dw		Trk1Ch1		;2
	db	Loop,5
	db	call
	dw		Trk3Ch1		;3
	db	EndLoop
	db	Loop,4
	db	call
	dw		Trk8Ch1		;8
	db	EndLoop
	db	call
	dw		Trk12Ch1		;12
	db	call
	dw		Trk13Ch1		;13
	db	Loop,10
	db	call
	dw		Trk3Ch1		;14
	db	EndLoop
	db	call
	dw		Trk24Ch1		;24
	db	call
	dw		Trk24Ch1		;25
	db	call
	dw		Trk26Ch1		;26
	db	call
	dw		Trk26Ch1		;27
	db	goto
	dw		Channel1
Channel2:
	db	call
	dw		Trk0Ch2		;0
	db	Loop,7
	db	call
	dw		Trk1Ch2		;1
	db	EndLoop
	db	call
	dw		Trk8Ch2		;8
	db	call
	dw		Trk9Ch2		;9
	db	call
	dw		Trk9Ch2		;10
	db	call
	dw		Trk9Ch2		;11
	db	Loop,10
	db	call
	dw		Trk1Ch2		;12
	db	EndLoop
	db	Loop,6
	db	call
	dw		Trk22Ch2		;22
	db	EndLoop
	db	goto
	dw		Channel2
Channel3:
	db	call
	dw		Hang64x2		;0
	db	call
	dw		Trk2Ch3		;2
	db	call
	dw		Trk3Ch3		;3
	db	Loop,8
	db	call
	dw		Trk4Ch3		;4
	db	EndLoop
	db	call
	dw		Hang64		;12
	db	call
	dw		Trk13Ch3		;13
	db	Loop,14
	db	call
	dw		Trk4Ch3		;14
	db	EndLoop
	db	goto
	dw		Channel3
;***************************************
;Channel 0
;***************************************
;---------------------------------------
;Track 0
;---------------------------------------
Trk0Ch0:
	db	Instrument,Sample3
	db	Loop,2
	db	24,2,22,1,24,2,22,1,24,3,22,1,24,4,24,2
	db	27,3,27,3,29,3,29,3,22,2,22,2
	db	EndLoop
	db	return
;---------------------------------------
;Track 5
;---------------------------------------
Trk5Ch0:
	db	Instrument,Sample3
	db	Loop,2
	db	26,2,24,1,26,2,24,1,26,3,24,1,26,4,26,2
	db	29,3,29,3,31,3,31,3,24,2,24,2
	db	EndLoop
	db	return
;---------------------------------------
;Track 9
;---------------------------------------
Trk9Ch0:
	db	Instrument,Sample3
	db	22,2,20,1
	db	Call
	dw		Trk9Ch0a
	db	27,3,20,2,20,2,26,2,20,1
	db	Call
	dw		Trk9Ch0a
	db	27,1,27,1,27,1,27,1,27,3
	db	return
Trk9Ch0a:
	db	22,2,20,1,22,3,20,1
	db	22,4,22,2,26,3,26,3,27,3
	db	return

;---------------------------------------
;Track 10
;---------------------------------------
Trk10Ch0:
	db	Instrument,Sample8
	db	8+12,16,12+12,8,5+12,8,8+12,16,12+12,8,5+12,8
	db	return
;---------------------------------------
;Track 11
;---------------------------------------
Trk11Ch0:
	db	Instrument,Sample8
	db	8+12,16,12+12,8,5+12,8,8+12,16,12+12,8,5+12,8
	db	return
;---------------------------------------
;Track 28
;---------------------------------------
Trk28Ch0:
	db	Instrument,Sample1
	db	Call
	dw		Trk28Ch0b
	db	Call
	dw		Trk28Ch0a
	db	15,3,15,2,15,1,15,2
	db	Call
	dw		Trk28Ch0b
	db	15,1,15,3,15,2,32,1,15,1,32,1,15,1,15,2,15,4
	db	return

Trk28Ch0b:
	db	Call
	dw		Trk28Ch0a
	db	15,1,15,2,15,2,15,1,15,2
	db	return
Trk28Ch0a:
	db	27,2,15,2,15,2,24,2
	db	return
;***************************************
;Channel 1
;***************************************
;---------------------------------------
;Track 0
;---------------------------------------
Trk0Ch1:
	db	pause,16
	db	Instrument,Sample1
	db	Call
	dw		Trk0Ch1a
	db	22,16,24,2
	db	Call
	dw		Trk0Ch1a
	db	22,2
	db	return
Trk0Ch1a:
	db	27,3,27,3,29,3,29,3,22,2
	db	return
;---------------------------------------
;Track 1
;---------------------------------------
Trk1Ch1:
	db	Instrument,Sample1
	db	Loop,2
	db	24,2,22,1,24,2,22,1,24,3,22,1,24,4,24,2
	db	Call
	dw		Trk0Ch1a
	db	22,2
	db	EndLoop
	db	return
;---------------------------------------
;Track 3
;---------------------------------------
Trk3Ch1:
	db	Instrument,Sample1
	db	Loop,3
	db	27,1,29,1,15,1,31,1,15,1,29,1,24,1,31,1
	db	15,1,15,1,29,1,15,1,29,1,15,1,15,1,31,1
	db	EndLoop
	db	15,1,15,1,29,1,31,1,15,1,29,1,32,1,15,1
	db	32,1,15,1,15,1,31,1,15,1,29,1,29,1,31,1
	db	return
;---------------------------------------
;Track 8
;---------------------------------------
Trk8Ch1:
	db	Instrument,Sample7
	db	Loop,2
	db	24,3,24,3,24,4,22,2,22,2,22,2
	db	24,3,24,3,24,4,27,2,27,4
	db	EndLoop
	db	return
;---------------------------------------
;Track 12
;---------------------------------------
Trk12Ch1:
	db	pause,3
	db	Instrument,Sample7
	db	Call
	dw		Trk12Ch1a
	db	24,4,27,2,27,4
	db	return
Trk12Ch1a:
	db	24,3,24,4,22,3,22,3,24,3,24,3,24,4,27,2
	db	27,4,24,3,24,3,24,4,22,3,22,3,24,3,24,3
	db	return

;---------------------------------------
;Track 13
;---------------------------------------
Trk13Ch1:
	db	pause,3
	db	Instrument,Sample7
	db	Call
	dw		Trk12Ch1a
	db	24,10
	db	return
;---------------------------------------
;Track 24
;---------------------------------------
Trk24Ch1:
	db	Instrument,Sample3
	db	15,3,24,3,15,4,15,2,24,6,15,2,24,4,15,2
	db	15,2,24,4,15,3,24,3,15,4,15,2,24,6,15,2
	db	24,2,24,2,15,4,24,2,24,2
	db	return
;---------------------------------------
;Track 26
;---------------------------------------
Trk26Ch1:
	db	Instrument,Sample8
	db	8+12,16,12+12,8,5+12,8,8+12,16,12+12,8,5+12,8
	db	return
;---------------------------------------
;Track 28
;---------------------------------------
Trk28Ch1:
	db	pause,2
	db	Instrument,Sample1
	db	15,2,15,4,15,1,15,2,15,2,15,1,15,4,15,2
	db	15,4,15,3,15,2,15,1,15,4
	db	15,2,15,4,15,1,15,2,15,2,15,1,15,2,15,1,15,3,15,3,15,2
	db	15,1,15,2,15,4
	db	return
;***************************************
;Channel 2
;***************************************
;---------------------------------------
;Track 0
;---------------------------------------
Trk0Ch2:
	db	Instrument,Sample8
	db	8+12,16,12+12,8,5+12,8,8+12,16,12+12,8,5+12,8
	db	return
;---------------------------------------
;Track 1
;---------------------------------------
Trk1Ch2:
	db	Instrument,Sample8
	db	8+12,16,12+12,8,5+12,8,8+12,16,12+12,8,5+12,8
	db	return
;---------------------------------------
;Track 8
;---------------------------------------
Trk8Ch2:
	db	Instrument,Sample7
	db	Loop,2
	db	24,3,24,3,24,4,22,2,22,2,22,2
	db	24,3,24,3,24,4,27,2,27,4
	db	EndLoop
	db	return
;---------------------------------------
;Track 9
;---------------------------------------
Trk9Ch2:
	db	Instrument,Sample7
	db	Loop,2
	db	24,3,24,3,24,4,22,3,22,3
	db	24,3,24,3,24,4,27,2,27,4
	db	EndLoop
	db	return
;---------------------------------------
;Track 22
;---------------------------------------
Trk22Ch2:
	db	Instrument,Sample3
	db	36,1,36,1,34,2
	db	Call
	dw		Trk22Ch2a
	db	36,1,36,3
	db	Call
	dw		Trk22Ch2a
	db	return
Trk22Ch2a:
	db	36,2,36,1,36,2,34,1,36,4
	db	36,2,36,1,36,3,36,3,38,2,38,1,38,2,34,2,34,2
	db	return
;---------------------------------------
;Track 28
;---------------------------------------
Trk28Ch2:
	db	Instrument,Sample1
	db	Loop,3
	db	27,1,29,1,15,1,31,1,15,1,29,1,24,1,31,1
	db	15,1,15,1,29,1,15,1,29,1,15,1,15,1,31,1
	db	EndLoop
	db	15,1,15,1,29,1,31,1,15,1,29,1,32,1,15,1
	db	32,1,15,1,15,1,31,1,15,1,29,1,29,1,31,1
	db	return
;***************************************
;Channel 3
;***************************************
;---------------------------------------
;Track 2
;---------------------------------------
Trk2Ch3:
	db	Loop,8
	db	Instrument,Sample4
	db	24,1
	db	Instrument,Sample5
	db	23,1,27,1,23,1,23,1,23,1,27,1,23,1
	db	EndLoop
	db	return
;---------------------------------------
;Track 3
;---------------------------------------
Trk3Ch3:
	db	Loop,3
	db	Call
	dw		Trk3Ch3a
	db	Instrument,Sample4
	db	24,1
	db	Instrument,Sample5
	db	23,1,27,1,23,1,23,1,23,1,27,1,23,1
	db	EndLoop

	db	Call
	dw		Trk3Ch3a
	db	Call
	dw		Trk13Ch3a
	db	return
Trk3Ch3a:
	db	Instrument,Sample4
	db	24,1
	db	Instrument,Sample5
	db	23,1
	db	Instrument,Sample6
	db	26,1
	db	Instrument,Sample2
	db	24,1
	db	Instrument,Sample5
	db	23,1,23,1
	db	Instrument,Sample2
	db	24,1
	db	Instrument,Sample5
	db	23,1
	db	return
;---------------------------------------
;Track 4
;---------------------------------------
Trk4Ch3:
	db	Call
	dw		Trk4Ch3a
	db	Call
	dw		Trk4Ch3b
	db	Call
	dw		Trk3Ch3a

	db	Instrument,Sample4
	db	24,1
	db	Instrument,Sample5
	db	23,1
	db	Instrument,Sample6
	db	26,1
	db	Instrument,Sample5
	db	23,1
	db	Instrument,Sample4
	db	24,1
	db	Instrument,Sample5
	db	23,1
	db	Instrument,Sample4
	db	24,1
	db	Instrument,Sample5
	db	23,1

	db	Call
	dw		Trk3Ch3a
	db	Call
	dw		Trk4Ch3b
	db	Call
	dw		Trk3Ch3a
	db	Call
	dw		Trk13Ch3a
	db	return
Trk4Ch3b:
	db	Instrument,Sample4
	db	24,1
	db	Instrument,Sample5
	db	23,1
	db	Instrument,Sample6
	db	26,1
	db	Instrument,Sample4
	db	24,1
	db	Instrument,Sample5
	db	23,1,23,1
	db	Instrument,Sample4
	db	24,1
	db	Instrument,Sample5
	db	23,1
	db	return
Trk4Ch3a:
	db	Instrument,Sample4
	db	24,1
	db	Instrument,Sample5
	db	23,1
	db	Instrument,Sample6
	db	26,1
	db	Instrument,Sample2
	db	24,1
	db	Instrument,Sample5
	db	23,1,28,1
	db	Instrument,Sample2
	db	24,1
	db	Instrument,Sample5
	db	23,1
	db	return

;---------------------------------------
;Track 13
;---------------------------------------
Trk13Ch3:
	db	Instrument,Sample4
	db	24,56
	db	return
Trk13Ch3a:
	db	Instrument,Sample4
	db	24,1,24,1
	db	Instrument,Sample6
	db	26,1
	db	Instrument,Sample4
	db	24,1
	db	Instrument,Sample5
	db	23,1
	db	Instrument,Sample4
	db	24,1,24,1
	db	Instrument,Sample5
	db	23,1
	db	return
;-----------------------------------------------------------------------------


	END
